#include <iostream.h>
#include "CWnCgi.h"
#include "CStringBuilder.h"

int main()
{
    cout << "Content-type: text/html\n\n";

    FILE *fp = fopen("patentworld.wnml","rt");
    fseek(fp,0,SEEK_END);
    int flen = ftell(fp);
    fseek(fp,0,SEEK_SET);
    char *buf = new char[flen+1];
    int tsize = 0;
    while((tsize=fread(buf+tsize,sizeof(char),flen,fp))>0) ;
    fclose(fp);

    CWnCgi *WnCgi = new CWnCgi();

    if(!WnCgi->getFormData()) {
	CStringBuilder *sb = new CStringBuilder(buf,"(olo)");
	sb->SetQString(1,"LoginTest.cgi");
	sb->SetString(2,"<input type=text name=userid size=10>");
	sb->SetString(3,"<input type=password name=passwd size=10>");
	sb->SetString(4,"<input type=submit value=Confirmation>");

	cout << sb->GetString() << endl;

	delete sb;
    }
    else {
	CStringBuilder *sb = new CStringBuilder(buf,"(olo)");
	sb->SetQString(1,"LoginTest.cgi");
	sb->SetString(2,WnCgi->getEntryDataByEntryName("userid"));
	sb->SetString(3,WnCgi->getEntryDataByEntryName("passwd"));
	sb->SetString(4,"<a href=LoginTest.cgi>Logout</a>");

	cout << sb->GetString() << endl;

	delete sb;
    }

    delete WnCgi;
    delete []buf;
}
